package com.yeswater.algorithm.leetcode.hot100;

import java.util.HashSet;

public class Code3 {

    public int lengthOfLongestSubstring(String s) {

        int len = s.length();
        int res = 0;

        // 右指针探测,左指针追到不重复的位置
        int l = 0, r = 0;
        HashSet<Character> set = new HashSet<>();
        while(r < len){
            char charR = s.charAt(r++);
            while (set.contains(charR)){
                char charL = s.charAt(l++);
                set.remove(charL);
            }
            set.add(charR);
            res = Math.max(r - l, res);
        }
        return res;

    }

}
